//package com.treasure.mall.zbq.common;
//
//import sun.misc.BASE64Decoder;
//import sun.misc.BASE64Encoder;
//
//import javax.crypto.Cipher;
//import javax.crypto.spec.SecretKeySpec;
//
///**
// * https://www.cnblogs.com/lzrabbit/p/3639503.html
// * @author guomw
// */
//@SuppressWarnings("restriction")
//public class EncryptUtil {
//
//    private static String key = "XjvDhKLvCsm9y7G7";
//
//    /**
//     * 加密
//     *
//     * @param str 字符串
//     * @return
//     * @throws Exception
//     */
//    public static String aesEncrypt(String str) throws Exception {
//        return aesEncrypt(str, key);
//    }
//    /**
//     * 解密
//     *
//     * @param str 字符串
//     * @return
//     * @throws Exception
//     */
//    public static String aesDecrypt(String str) throws Exception {
//        return aesDecrypt(str, key);
//    }
//
//    public static String aesEncrypt(String str, String key) throws Exception {
//        if (str == null || key == null) {
//            return null;
//        }
//        Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
//        cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(key.getBytes("utf-8"), "AES"));
//        byte[] bytes = cipher.doFinal(str.getBytes("utf-8"));
//        return new BASE64Encoder().encode(bytes);
//    }
//
//    public static String aesDecrypt(String str, String key) throws Exception {
//        if (str == null || key == null) {
//            return null;
//        }
//        Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
//        cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(key.getBytes("utf-8"), "AES"));
//        byte[] bytes = new BASE64Decoder().decodeBuffer(str);
//        bytes = cipher.doFinal(bytes);
//        return new String(bytes, "utf-8");
//    }
//}